 /*	
  *				
  *					ISNW ---- It is a war.It is not warcraft!
  *
  *
  *					Author:					zhoukeli(haxixi_keli)
  *					Filename:				IReferenceCounted.h
  *					CreateTime:				2008/12/14
  *					ModifyTime:				2008/12/14
  *
  */

#ifndef __ISNW_I_REFERENCECOUNTED_H__
#define __ISNW_I_REFERENCECOUNTED_H__

#include "isnwTypes.h"

namespace ISNW
{
	class IReferenceCounted
	{
	public:
		//! constructor
		IReferenceCounted():reference(1){}

		//! destructor
		virtual ~IReferenceCounted(){}

	public:
		//! function
		void grab() const
		{
			reference++;
		}

		bool drop() const
		{
			reference--;
			if(reference <= 0)
			{
				delete this;
				return true;
			}

			return false;
		}
		
	protected:
		mutable s32 reference;
	};
} // end namespace ISNW
#endif